/**
 *
 * User: Zhikang.Peng
 * Date: 2018/04/12 16:49
 */
package comparisons

import (
	"gitee.com/thghh/jvmgo/instructions/base"
	"gitee.com/thghh/jvmgo/rtda"
)

// 比较栈顶两引用型数值，当结果相等时跳转
type IF_ACMPEQ struct{ base.BranchInstruction }

func (self *IF_ACMPEQ) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	ref2 := stack.PopReference()
	ref1 := stack.PopReference()
	if ref1 == ref2 {
		base.Branch(frame, self.Offset)
	}
}

// 比较栈顶两引用型数值，当结果不相等时跳转
type IF_ACMPNE struct{ base.BranchInstruction }

func (self *IF_ACMPNE) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	ref2 := stack.PopReference()
	ref1 := stack.PopReference()
	if ref1 != ref2 {
		base.Branch(frame, self.Offset)
	}
}
